﻿/*
 * This software is the confidential and proprietary
 * information of NetBay
 * Such confidential information should not be disclosed
 * NetBay copyright(c) 2011
 */

#region Using

using System;
using System.Collections.Generic;
using NetBay.Core.BusinessEntities.Connectors;
using System.Data;
using Rio.Framework.DataAccess;
using NetBay.Core.BusinessEntities;

#endregion Using

namespace Rio.Manager.Business.Repository.Translator
{
    public class ConnectorTranslator
    {
        #region Selection

        /// <summary>Get connector list name.</summary>
        /// <param name="P_oDbDataReader">The data reader</param>
        /// <returns></returns>
        public static List<string> GetConnectorNameList(IDataReader P_oDbDataReader)
        {
            //Variable declaration.
            var l_oConnectorListName = new List<string>();

            //Log.
            NetBay.Core.Log.LogManager.Instance().LogDebug("ConnectorTranslator.GetConnectorNameList");

            try
            {
                using (P_oDbDataReader)
                {
                    while (P_oDbDataReader.Read())
                    {
                        //List Connector Value.
                        l_oConnectorListName.Add(P_oDbDataReader["RECON_ID"].ToString() + ";" + P_oDbDataReader["RECON_LIBELLE"].ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                NetBay.Core.Log.LogManager.Instance().LogError("ConnectorTranslator.GetConnectorNameList Exception [" + ex.Message + "]");
            }
            return l_oConnectorListName;
        }

        /// <summary>Get connector information list.</summary>
        /// <param name="P_oDbDataReader">The data reader</param>
        /// <returns>Connector information list</returns>
        public static List<Connector> GetConnectorInformationList(IDataReader P_oDbDataReader)
        {
            //Variable declaration.
            List<Connector> l_oConnectorInformationList = new List<Connector>();

            //Log.
            NetBay.Core.Log.LogManager.Instance().LogDebug("ConnectorTranslator.GetConnectorInformationList");

            try
            {
                using (P_oDbDataReader)
                {
                    while (P_oDbDataReader.Read())
                    {
                        //Variable declaration.
                        Connector l_oConnectorInformation = new Connector();

                        //Connector value.
                        l_oConnectorInformation.ConnectorId = Convert.ToInt32(P_oDbDataReader["RECON_ID"].ToString());
                        l_oConnectorInformation.ConnectorName = P_oDbDataReader["RECON_LIBELLE"].ToString();
                        l_oConnectorInformation.ConnectorDescription = P_oDbDataReader["RECON_DESCRIPTION"].ToString();
                        l_oConnectorInformation.OrganizationCode = Convert.ToInt32(P_oDbDataReader["re_id"].ToString());
                        l_oConnectorInformation.OrganizationName = P_oDbDataReader["re_nom"].ToString();
                        l_oConnectorInformation.OrganizationDescritpion = P_oDbDataReader["re_description"].ToString();
                        l_oConnectorInformation.FolderTypeId = Convert.ToInt32(P_oDbDataReader["RP_TD_ID"].ToString());
                        l_oConnectorInformation.FolderTableTypeName = P_oDbDataReader["RP_TD_TABLE"].ToString();
                        l_oConnectorInformation.FolderTypeName = P_oDbDataReader["RP_TD_LIBELLE"].ToString();

                        //Correspondence Connector.
                        l_oConnectorInformation.LstConnectorCorrespondence = ConnectorTranslator.GetConnectorCorrespondenceList(DA_Connector.GetConnectorCorrespondenceList(l_oConnectorInformation.ConnectorId));

                        //Parameters connector.
                        l_oConnectorInformation.LstConnectorParameters = ConnectorTranslator.GetConnectorParametersList(DA_Connector.GetConnectorParametersList(l_oConnectorInformation.ConnectorId));

                        //Add Connector in the list.
                        l_oConnectorInformationList.Add(l_oConnectorInformation);
                    }
                }
            }
            catch (Exception ex)
            {
                NetBay.Core.Log.LogManager.Instance().LogError("ConnectorTranslator.GetConnectorInformationList Exception [" + ex.Message + "]");
            }
            return l_oConnectorInformationList;
        }

        /// <summary>Get connector correspondence list.</summary>
        /// <param name="P_oDbDataReader">The data reader</param>
        /// <returns>Connector correspondence list</returns>
        public static List<ConnectorCorrespondence> GetConnectorCorrespondenceList(IDataReader P_oDbDataReader)
        {
            //Variable declaration.            
            List<ConnectorCorrespondence> l_oConnectorCorrespondenceList = new List<ConnectorCorrespondence>();

            //Log.
            NetBay.Core.Log.LogManager.Instance().LogDebug("ConnectorTranslator.GetConnectorCorrespondenceList");

            try
            {
                using (P_oDbDataReader)
                {
                    while (P_oDbDataReader.Read())
                    {
                        //Variable declaration.
                        ConnectorCorrespondence l_oConnectorCorrespondence = new ConnectorCorrespondence();

                        //Connector value.
                        l_oConnectorCorrespondence.ConnectorCorrespondenceId = Convert.ToInt32(P_oDbDataReader["recor_id"].ToString());
                        l_oConnectorCorrespondence.ConnectorId = Convert.ToInt32(P_oDbDataReader["recon_id"].ToString());
                        l_oConnectorCorrespondence.ConnectorIndexCorrespondenceId = Convert.ToInt32(P_oDbDataReader["RP_CH_NO"].ToString());
                        l_oConnectorCorrespondence.ConnectorIndexCorrespondenceName = P_oDbDataReader["RP_CH_NOM"].ToString();
                        l_oConnectorCorrespondence.ConnectorIndexCorrespondencePosition = Convert.ToInt32(P_oDbDataReader["recor_index_pos"].ToString());
                        l_oConnectorCorrespondence.ConnectorIndexCorrespondenceDescription = P_oDbDataReader["recor_description"].ToString();

                        //Add Connector in the list.
                        l_oConnectorCorrespondenceList.Add(l_oConnectorCorrespondence);
                    }
                }
            }
            catch (Exception ex)
            {
                NetBay.Core.Log.LogManager.Instance().LogError("ConnectorTranslator.GetConnectorCorrespondenceList Exception [" + ex.Message + "]");
            }
            return l_oConnectorCorrespondenceList;
        }

        /// <summary>Get connector parameters list.</summary>
        /// <param name="P_oDbDataReader">The data reader</param>
        /// <returns>Connector parameters list</returns>
        public static List<ConnectorParameters> GetConnectorParametersList(IDataReader P_oDbDataReader)
        {
            //Variable declaration.            
            List<ConnectorParameters> l_oConnectorParametersList = new List<ConnectorParameters>();

            //Log.
            NetBay.Core.Log.LogManager.Instance().LogDebug("ConnectorTranslator.GetConnectorParametersList");

            try
            {
                using (P_oDbDataReader)
                {
                    while (P_oDbDataReader.Read())
                    {
                        //Variable declaration.
                        ConnectorParameters l_oConnectorParameters = new ConnectorParameters();

                        //Connector value.
                        l_oConnectorParameters.ConnectorParamId = Convert.ToInt32(P_oDbDataReader["REPAR_ID"].ToString());
                        l_oConnectorParameters.ConnectorCustomerParam = P_oDbDataReader["REPAR_ERP_VALEUR"].ToString();
                        l_oConnectorParameters.ConnectorRioParam = P_oDbDataReader["REPAR_RIO_VALEUR"].ToString();
                        l_oConnectorParameters.ConnectorDescriptionParam = P_oDbDataReader["REPAR_DESCRIPTION"].ToString();

                        //Add Connector in the list.
                        l_oConnectorParametersList.Add(l_oConnectorParameters);
                    }
                }
            }
            catch (Exception ex)
            {
                NetBay.Core.Log.LogManager.Instance().LogError("ConnectorTranslator.GetConnectorParametersList Exception [" + ex.Message + "]");
            }
            return l_oConnectorParametersList;
        }

        /// <summary>Get folder type indexes correspondence list.</summary>
        /// <param name="P_oDbDataReader">The data reader</param>  
        /// <returns>Folder type indexes correspondence list.</returns>
        public static List<ConnectorCorrespondence> GetFolderTypeIndexCorrespondanceList(IDataReader P_oDbDataReader)
        {
            //Log.
            NetBay.Core.Log.LogManager.Instance().LogDebug("ConnectorTranslator.GetFolderTypeIndexCorrespondanceList");

            //Variable declaration.            
            List<ConnectorCorrespondence> l_oFolderTypeIndexCorrespondanceList = new List<ConnectorCorrespondence>();

            try
            {
                using (P_oDbDataReader)
                {
                    while (P_oDbDataReader.Read())
                    {
                        //Variable declaration.
                        ConnectorCorrespondence l_oConnectorCorrespondence = new ConnectorCorrespondence();

                        //Connector value.                       
                        l_oConnectorCorrespondence.ConnectorIndexCorrespondenceName = P_oDbDataReader["RP_CH_NOM"].ToString();
                        l_oConnectorCorrespondence.ConnectorIndexCorrespondencePosition = Convert.ToInt32(P_oDbDataReader["Position"].ToString());
                        l_oConnectorCorrespondence.ConnectorIndexCorrespondenceDescription = "";

                        //Add Connector in the list.
                        l_oFolderTypeIndexCorrespondanceList.Add(l_oConnectorCorrespondence);
                    }
                }
            }
            catch (Exception ex)
            {
                NetBay.Core.Log.LogManager.Instance().LogError("ConnectorTranslator.GetFolderTypeIndexCorrespondanceList Exception [" + ex.Message + "]");
            }
            return l_oFolderTypeIndexCorrespondanceList;
        }

        #endregion Selection
    }
}
